export const getOffset = function ($el) {
  let x = $el.offsetLeft
  let y = $el.offsetTop
  while ($el.offsetParent !== document.body) {
    x = x + $el.offsetParent.offsetLeft
    y = y + $el.offsetParent.offsetTop
    $el = $el.offsetParent
  }
  return {x, y}
}

export const jsonToQueryStr = (data = {}) => {
  let query = []
  for (let key in data) {
    data.hasOwnProperty(key) && query.push(`${key}=${encodeURIComponent(data[key])}`)
  }
  return query.join('&')
}
